<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="草药处方状态：status  0作废 1未缴费 2已缴费 3已过期" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择草药处方状态：status  0作废 1未缴费 2已缴费 3已过期" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="总金额" prop="amount">
        <el-input
          v-model="queryParams.amount"
          placeholder="请输入总金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处方名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入处方名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="治法" prop="therapy">
        <el-input
          v-model="queryParams.therapy"
          placeholder="请输入治法"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="治法详情" prop="therapyDetails">
        <el-input
          v-model="queryParams.therapyDetails"
          placeholder="请输入治法详情"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医嘱" prop="medicalAdvice">
        <el-input
          v-model="queryParams.medicalAdvice"
          placeholder="请输入医嘱"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="付数" prop="pairNum">
        <el-input
          v-model="queryParams.pairNum"
          placeholder="请输入付数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="门诊Id(挂号号id)" prop="registrationId">
        <el-input
          v-model="queryParams.registrationId"
          placeholder="请输入门诊Id(挂号号id)"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="频次" prop="frequency">
        <el-input
          v-model="queryParams.frequency"
          placeholder="请输入频次"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用法" prop="usageMeans">
        <el-input
          v-model="queryParams.usageMeans"
          placeholder="请输入用法"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="开立人" prop="createStaffId">
        <el-input
          v-model="queryParams.createStaffId"
          placeholder="请输入开立人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dms:herbal_prescription_record:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dms:herbal_prescription_record:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dms:herbal_prescription_record:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dms:herbal_prescription_record:export']"
        >导出</el-button>
      </el-col>
      <div class="top-right-btn">
        <el-tooltip class="item" effect="dark" content="刷新" placement="top">
          <el-button size="mini" circle icon="el-icon-refresh" @click="handleQuery" />
        </el-tooltip>
        <el-tooltip class="item" effect="dark" :content="showSearch ? '隐藏搜索' : '显示搜索'" placement="top">
          <el-button size="mini" circle icon="el-icon-search" @click="showSearch=!showSearch" />
        </el-tooltip>
      </div>
    </el-row>

    <el-table v-loading="loading" :data="herbal_prescription_recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="草药处方状态：status  0作废 1未缴费 2已缴费 3已过期" align="center" prop="status" />
      <el-table-column label="总金额" align="center" prop="amount" />
      <el-table-column label="处方名" align="center" prop="name" />
      <el-table-column label="治法" align="center" prop="therapy" />
      <el-table-column label="治法详情" align="center" prop="therapyDetails" />
      <el-table-column label="医嘱" align="center" prop="medicalAdvice" />
      <el-table-column label="付数" align="center" prop="pairNum" />
      <el-table-column label="门诊Id(挂号号id)" align="center" prop="registrationId" />
      <el-table-column label="频次" align="center" prop="frequency" />
      <el-table-column label="用法" align="center" prop="usageMeans" />
      <el-table-column label="类型" align="center" prop="type" />
      <el-table-column label="开立人" align="center" prop="createStaffId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dms:herbal_prescription_record:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dms:herbal_prescription_record:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改草药处方对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="草药处方状态：status  0作废 1未缴费 2已缴费 3已过期">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="总金额" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入总金额" />
        </el-form-item>
        <el-form-item label="处方名" prop="name">
          <el-input v-model="form.name" placeholder="请输入处方名" />
        </el-form-item>
        <el-form-item label="治法" prop="therapy">
          <el-input v-model="form.therapy" placeholder="请输入治法" />
        </el-form-item>
        <el-form-item label="治法详情" prop="therapyDetails">
          <el-input v-model="form.therapyDetails" placeholder="请输入治法详情" />
        </el-form-item>
        <el-form-item label="医嘱" prop="medicalAdvice">
          <el-input v-model="form.medicalAdvice" placeholder="请输入医嘱" />
        </el-form-item>
        <el-form-item label="付数" prop="pairNum">
          <el-input v-model="form.pairNum" placeholder="请输入付数" />
        </el-form-item>
        <el-form-item label="门诊Id(挂号号id)" prop="registrationId">
          <el-input v-model="form.registrationId" placeholder="请输入门诊Id(挂号号id)" />
        </el-form-item>
        <el-form-item label="频次" prop="frequency">
          <el-input v-model="form.frequency" placeholder="请输入频次" />
        </el-form-item>
        <el-form-item label="用法" prop="usageMeans">
          <el-input v-model="form.usageMeans" placeholder="请输入用法" />
        </el-form-item>
        <el-form-item label="类型">
          <el-select v-model="form.type" placeholder="请选择类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="开立人" prop="createStaffId">
          <el-input v-model="form.createStaffId" placeholder="请输入开立人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listHerbal_prescription_record, getHerbal_prescription_record, delHerbal_prescription_record, addHerbal_prescription_record, updateHerbal_prescription_record, exportHerbal_prescription_record } from "@/api/dms/herbal_prescription_record";

export default {
  name: "Herbal_prescription_record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 草药处方表格数据
      herbal_prescription_recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: null,
        amount: null,
        name: null,
        therapy: null,
        therapyDetails: null,
        medicalAdvice: null,
        pairNum: null,
        registrationId: null,
        frequency: null,
        usageMeans: null,
        type: null,
        createStaffId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询草药处方列表 */
    getList() {
      this.loading = true;
      listHerbal_prescription_record(this.queryParams).then(response => {
        this.herbal_prescription_recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        status: 0,
        createTime: null,
        amount: null,
        name: null,
        therapy: null,
        therapyDetails: null,
        medicalAdvice: null,
        pairNum: null,
        registrationId: null,
        frequency: null,
        usageMeans: null,
        type: null,
        createStaffId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加草药处方";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHerbal_prescription_record(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改草药处方";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateHerbal_prescription_record(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addHerbal_prescription_record(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除草药处方编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delHerbal_prescription_record(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有草药处方数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportHerbal_prescription_record(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
